package fileIO;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import org.jdom.Element;

import data.ClockInterface;
import data.FilePath;

public class EmailNoticeWriter {
	
	public static void write(HashMap<String, ArrayList<String>> reminderMap) throws ParseException{
		Element root = new Element("EmailReminder");
		
		Object[] keyList = reminderMap.keySet().toArray();
		
		for(int i=0;i<keyList.length;i++){
			ArrayList<String> list = reminderMap.get(keyList[i]);
			Calendar reminderDate = ClockInterface.StrToCalendar(list.get(1));
			Calendar todayDate = ClockInterface.StrToCalendar(ClockInterface.getTodayDate("MM/dd/yyyy"));
			if (ClockInterface.aAfterB(todayDate,  reminderDate,7))
				continue;
			Element shipmentReminder = new Element("ShipmentSent");			
			shipmentReminder.setAttribute("Key",(String)keyList[i]);
			shipmentReminder.setAttribute("reminderCount",list.get(0));
			shipmentReminder.setAttribute("reminderDate",list.get(1));
			
			root.addContent(shipmentReminder);
		}
		XMLWriter.writeDocument(root, FilePath.REMINDER_LIST);
	}
}
